package com.sense.kukoo.biz_library.adapter

import android.view.View
import com.sense.kukoo.biz_library.adapter.provider.HistoryItemProvider
import com.sense.kukoo.common.repo.bean.HistoryItemBean
import com.sense.kukoo.common.wiget.adapter.MultiItemAdapter

class HistoryAdapter(
    data: MutableList<HistoryItemBean>,
    val mListener: HistoryEventListener
) :
    MultiItemAdapter<HistoryItemBean>(data) {

    private val TAG: String = javaClass.simpleName

    val historyItemProvider: HistoryItemProvider
    var isEditMode: Boolean = false
        set(value) {
            field = value
            historyItemProvider.isEditMode = value
            //退出edit模式时，将isChecked复位
            if(!value){
                for (i in list){
                    i.isChecked = false
                }
            }
            //
            notifyDataSetChanged()
        }

    init {
        historyItemProvider = HistoryItemProvider(mListener)
        addItemProvider(historyItemProvider)
    }

    override fun getItemType(data: MutableList<HistoryItemBean>, position: Int): Int {
        return HistoryItemBean.TYPE_DEF
    }

    interface HistoryEventListener {

        fun onItemClick(itemView: View, bean: HistoryItemBean)
        fun onItemLongClick(itemView: View, bean: HistoryItemBean)
        fun onItemCheckedChanged(itemView: View, bean: HistoryItemBean)

    }
}